﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VirtualPress.Portal.WebLogic;
using VirtualPress.Portal.Biz;
using VirtualPress.Infrastructure.Entities.Entity;

namespace VirtualPress.Portal.Web.Areas.Books.Controllers
{
#if !DEBUG
    [ErrorHandle]
#endif
    [Compress]
    public class HomeController : SiteBaseController
    {
        //
        // GET: /Books/Home/

        public ActionResult List(int page = 0)
        {
            ViewBag.Books = iCache.Get("CommonBiz.GetAllBook_" + page + "_12", () =>
            {
                return new ItemListBox<Book>(CommonBiz.GetAllBook(page, 12))
                    .BuildPage(CommonBiz.GetPageOfBooks(), page, 12,
                    new PageParameter() { Style = "home" });
            }, 600);
            return View();
        }

        public ActionResult Detail(int id)
        {
            var book = new Book().Find(id.ToString());
            if (book == null)
            {
                return RedirectToAction("List");
            }
            ViewBag.Book = book;
            return View();
        }
    }
}
